import 'package:flutter/material.dart';
import 'api/item.dart';

class ItemTile extends StatelessWidget {
  final Item item;

  const ItemTile({super.key, required this.item});

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.all(8),
      child: ListTile(
        leading: AspectRatio(
          aspectRatio: 1,
          child: Container(color: item.color),
        ),
        title: Text(
          item.name,
          style: Theme.of(context).textTheme.headlineLarge,
        ),
        trailing: Text('\$ ${(item.price / 100).toStringAsFixed(2)}'),
      ),
    );
  }
}

class LoadingItemTile extends StatelessWidget {
  const LoadingItemTile({super.key});

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.all(8),
      child: ListTile(
        leading: AspectRatio(aspectRatio: 1, child: Placeholder()),
        title: Text('...', style: Theme.of(context).textTheme.headlineLarge),
        trailing: Text('\$ ...'),
      ),
    );
  }
}
